// 创建index页面的vue实例
const baseUrl = "http://localhost:8080"
let app = new Vue({
    el: "#vue-app",
    data: {
        message: "hello world",
        cates: [],
        // 首页广告
        ads: [],
        all_house: [],
        news: []
    },
    methods: {
        // 获取首页菜单cates
        getCates() {
            // API：http://localhost:8080/app/category.json
            axios({
                method: "get",
                url: baseUrl + "/app/category.json",
            }).then(response => {
                // console.log("debug => ",response);
                this.cates = response.data.cates;
            }).catch(error => {
                console.log("请求失败！");
            });
        },
        // 获取首页广告信息(ads)
        getAdsList() {
            /*
            API：http://localhost:8080/hotel/ads/list
            请求参数：
            {
                "page": "1", 页码
                "limit": "10", 每页显示记录数
                "sidx": "id", 排序字段
                "order": "asc/desc" 排序类型
            }
            */
            axios({
                mehtod: "get",
                url: baseUrl + "/hotel/ads/list",
                data: {
                    page: "1",
                    limit: "10"
                }
            }).then(response => {
                // console.log("debug => ",response);、
                this.ads = response.data.page.list;
            }).catch(error => {
                console.log("请求失败");
            })
        },
        // 获取首页房间信息(house)
        getAllHouse() {
            /*
            API：http://localhost:8080/hotel/house/list
            请求参数：{page: 1,limit: 10,sidx: "price",order: "desc"}
             */
            axios({
                method: "get",
                url: baseUrl + "/hotel/house/list",
                data: {
                    page: 1,
                    limit: 10,
                    sidx: "price",
                }
            }).then(response => {
                // console.log("debug => ",response);
                this.all_house = response.data.page.list;
            }).catch(error => {
                console.log("请求失败！");
            })
        },
        // 获取首页新闻信息(news)
        getIndexNews() {
            /*
            API：http://localhost:8080/hotel/news/list
            请求参数：{page: 1,limit: 10,sidx: "id",order: "desc"}
            */
            axios({
                method: "get",
                url: baseUrl + "/hotel/news/list",
                data: {
                    page: 1,
                    limit: 10,
                    sidx: "id",
                }
            }).then(response => {
                // console.log("debug => ",response);
                this.news = response.data.page.list;
            }).catch(error => {
                console.log("请求失败！");
            })
        }
    },
    // 生命周期函数，vue实例初始化完成时执行
    created() {
        this.getCates();
        this.getAdsList();
        this.getAllHouse();
        this.getIndexNews();
    },
})